﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ajeelee.Core.Utils;
using AiLuWeb.Business;
using AiLuWeb.Model;
using AiLuWeb.WebSite.Code;

namespace AiLuWeb.WebSite.WebAdmin
{
    public partial class LanMuEdit : AuthPageBase
    {
        protected int id;
        protected LanMuInfo info = new LanMuInfo();
        ILanMuInfoBusiness lanMuInfoBll = new LanMuInfoBusinessFactory().CreateLanMuInfoBusiness();

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            id = QueryParamInt32("id");
            try
            {
                if (id > 0)
                {
                    info = lanMuInfoBll.GetById(id);
                    if (info != null)
                    {
                        if (IsPost)
                        {
                            IninInfo();
                            lanMuInfoBll.Update(info);

                            Function.RemoveCacheObject("/cache/parentlanmu/" + info.PId);
                            System.Threading.Thread.Sleep(500);
                            Page_GoTo("LanMuList.aspx?pid=" + info.PId);
                        }
                    }
                }
                else
                {
                    if (QueryParamInt32("pid") > 0)
                    {
                        info.PId = QueryParamInt32("pid");
                    }
                    else
                    {

                    }
                    if (IsPost)
                    {
                        IninInfo();

                        info.User = User.Identity.Name;
                        info.InDate = DateTime.Now;
                        info.InIP = IPAddress;

                        lanMuInfoBll.Insert(info);
                        //Function.RemoveCacheObject("/cache/menu/" + pid);
                        System.Threading.Thread.Sleep(500);
                        Page_GoTo("LanMuList.aspx?pid=" + info.PId);
                    }
                }
            }
            catch (Exception ex)
            {
                Function.WriteErrorLog(ex);
            }
        }

        private void IninInfo()
        {
            info.PId = FormParamInt32("pid");
            info.Name = FormParam("name");
            info.Content = FormParam("content");
            info.EnableCache = FormParamInt32("enableCache");
            info.SourceUrl = FormParam("sourceUrl");
            info.UrlName = FormParam("urlName");
            info.Sort = FormParamInt32("sort");
            info.Pic = FormParam("faceImg");

            info.UpDate = DateTime.Now;
            info.UpIP = IPAddress;
        }
    }
}